package jmine.tec.web.front.domain;

import static javax.persistence.InheritanceType.SINGLE_TABLE;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import jmine.tec.persist.annotation.Alias;
import jmine.tec.persist.annotation.Comment;
import jmine.tec.persist.annotation.Constraint;
import jmine.tec.persist.annotation.Index;
import jmine.tec.persist.annotation.UniqueConstraint;

import org.hibernate.criterion.Criterion;

import bancosys.tec.component.Documentation;
import bancosys.tec.persist.bussobj.PersistableBusinessObject;

/**
 * @author lundberg
 * @param <V> value type
 */
@Entity
@Alias("BORQVL")
@Constraint(suffix = "JT_0")
@Inheritance(strategy = SINGLE_TABLE)
@Table(name = "BACK_OFFICE_REQUEST_VALUE")
@Documentation("VALORES DE REQUISICOES DE BACK OFFICE.")
@SequenceGenerator(name = "SEQ_BORQVL", sequenceName = "SEQ_BORQVL")
@DiscriminatorColumn(name = "TP", discriminatorType = DiscriminatorType.INTEGER)
@Comment(table = "BACK_OFFICE_REQUEST_VALUE", column = "TP", value = "TIPO DE VALOR.")
@UniqueConstraint(suffix = "JT_0", columns = { "COD_BACK_OFFICE_REQUEST", "COD_BACK_OFFICE_REQ_PROP" })
public abstract class BackOfficeRequestValue<V> extends PersistableBusinessObject {

    private Long id;

    private BackOfficeRequest request;

    private BackOfficeRequestProperty property;

    private V value;

    /**
     * Constructor
     */
    public BackOfficeRequestValue() {
    }

    /**
     * Constructor
     * 
     * @param property property
     * @param value value
     */
    public BackOfficeRequestValue(BackOfficeRequestProperty property, V value) {
        this.property = property;
        this.value = value;
    }

    /**
     * @return the id
     */
    @Id
    @GeneratedValue(generator = "SEQ_BORQVL")
    @Column(name = "COD_BACK_OFFICE_REQUEST_VALUE", nullable = false)
    @Documentation("CODIGO DO VALOR DA REQUISICAO.")
    public Long getId() {
        return this.id;
    }

    /**
     * @return the request
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @Index(suffix = "JT_0")
    @JoinColumn(name = "COD_BACK_OFFICE_REQUEST", nullable = false)
    @Documentation("CODIGO DA REQUISICAO QUE POSSUI O VALOR.")
    public BackOfficeRequest getRequest() {
        return this.request;
    }

    /**
     * @return the property
     */
    @ManyToOne(fetch = FetchType.LAZY)
    @Index(suffix = "JT_1")
    @JoinColumn(name = "COD_BACK_OFFICE_REQ_PROP", nullable = false)
    @Documentation("CODIGO DA PROPRIEDADE QUE ESTE VALOR REPRESENTA")
    public BackOfficeRequestProperty getProperty() {
        return this.property;
    }

    /**
     * @return the value
     */
    @Transient
    public V getValue() {
        return this.value;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param request the request to set
     */
    public void setRequest(BackOfficeRequest request) {
        this.request = request;
    }

    /**
     * @param property the property to set
     */
    public void setProperty(BackOfficeRequestProperty property) {
        this.property = property;
    }

    /**
     * @param value the value to set
     */
    public void setValue(V value) {
        this.value = value;
    }

    /**
     * Expression used to filter property value
     * 
     * @return expression filter
     */
    @Transient
    public abstract Criterion getCriteriaExpression();
}
